from app import db
from flask import jsonify
from ..domain.log import Log
from ..opencv.camera import Camera


def add_log(log):
    db.session.add(log)
    db.session.commit()


def get_log_by_roomid(roomid):
    lList = Log.query.filter(Log.roomId == roomid)
    return lList


def get_log_by_search(roomid, keyword):
    str = keyword + '%%'
    lList = Log.query.filter(Log.roomId == roomid, Log.time.startswith(keyword))
    return lList


def delete_log_by_path(path):
    log = Log.query.filter(Log.video == path).first()
    db.session.delete(log)
    db.session.commit()
